import {createStore} from 'redux'//用于创建仓库
import {combineReducers} from 'redux'//
const initialState = {//state数据
    cart: [
      {
        product: 'bread 700g',
        quantity: 2,
        unitCost: 90
      },
      {
        product: 'milk 500ml',
        quantity: 1,
        unitCost: 47
      }
    ],
    count:1
  }
  const ADD_TO_CART = 'ADD_TO_CARTa';
  const cartReducer = function(state=initialState, action) {//数据与action提交类型
      switch(action.type){
        case 'ADD_TO_CART':
          // return {
          //   cart:state.cart.pop()
          // }
          return{
            cart:state.cart.push(action.payload)
          };break;
        case 'on_open':
          return {
            count:state.count+action.payload
          }
      }
      return state;
  }
   const allReducers = {//多个state数据集合
     product:cartReducer
   }
  
   
 let a=combineReducers(allReducers)//通过com管理
export  const store=createStore(a)//仓库
const e=store.getState();
 //console.log( e.products)
 
 function addToCart(product, quantity, unitCost) {//actioc提交方法 具有属性与形参
  return {
    type: 'ADD_TO_CART',
    payload: { product, quantity, unitCost }
  }
}
 const sta=createStore(cartReducer)
sta.dispatch(addToCart('Coffee 500gm', 2, 250));
